package com.itheima.controller;

import com.itheima.Service.ClazzService;
import com.itheima.Service.StudentService;
import com.itheima.entity.Student;
import com.itheima.entity.StudentQueryParam;
import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {
    private static final org.slf4j.Logger log = LoggerFactory.getLogger(DeptController.class);

    @Autowired
    private StudentService studentService;

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @GetMapping("/students")
    public Result Page(StudentQueryParam param) {
        log.info("学员分页查询：{}", param);
        PageBean pagebean = studentService.page(param);
        return Result.success(pagebean);
    }

    @GetMapping("/students/{id}")
    public Result getByStudentId(@PathVariable Integer id) {
        log.info("获取班级列表：{}", id);
        Student student = studentService.getByStudentId(id);
        return Result.success(student);
    }

    @DeleteMapping ("/students")
    public Result delete(@RequestParam List<Integer> ids) {
        log.info("删除学生：{}", ids);
        studentService.delete(ids);
        return Result.success();
    }

    @PostMapping ("/students")
    public Result add(@RequestBody Student student) {
        log.info("添加学员：{}", student);
        studentService.add(student);
        return Result.success();
    }

    @PutMapping ("/students")
    public Result update(@RequestBody Student student) {
        log.info("修改学员：{}", student);
        studentService.update(student);
        return Result.success();
    }

    @PutMapping ("/students/violation/{id}/{score}")
    public Result UpdateViolation(@PathVariable Integer id, @PathVariable Integer score) {
        log.info("修改学员违纪信息：{},{}", id, score);
        studentService.UpdateScore(id, score);
        return Result.success();
    }
}
